#ifndef DATEDIFFCALCULATOR_H
#define DATEDIFFCALCULATOR_H

#include <iostream>
#include <ctime>
#include <conio.h>

using namespace std;

class fuction4 {
public:
    void Calculate() {
        int aak, aal, aam;
        cout << "请输入要比较的日期(格式:YYYY MM DD): ";
        cin >> aak >> aal >> aam;

        // 构建用户输入的时间结构
        tm input = {};
        input.tm_year = aak - 1900;  // tm_year从1900开始
        input.tm_mon = aal - 1;      // tm_mon从0开始
        input.tm_mday = aam;
        time_t input_time = mktime(&input);  // 转换为时间戳
        if (input_time == -1) {
            cout << "输入的日期无效，请检查后重试。" << endl;
            return;
        }

        time_t now = time(nullptr);
        tm* now_tm = localtime(&now);
        cout << "今天是：" << (now_tm->tm_year + 1900) << "-"
             << (now_tm->tm_mon + 1) << "-"
             << now_tm->tm_mday << endl;
        // 计算天数差(秒数转天数)
        double second = difftime(input_time, now);
        int days = (int)(second / (60 * 60 * 24));
        // 输出结果
        cout << aak << "年" << aal << "月" << aam;
        if (days > 0) {
            cout << " 比今天晚 " << days << " 天。" << endl;
        } else if (days < 0) {
            cout << " 比今天早 " << -days << " 天。" << endl;
        } else {
            cout << " 您输入的日期是今天" << endl;
        }
        cout << "按任意键返回菜单..." << endl;
        _getch();
    }
};
#endif